<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
    <title>ShellCheck: SC2148 – Tips depend on target shell and yours is unknown. Add a shebang.</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
  </head>
  <body style="margin-left: auto; margin-right: auto; max-width: 800px">
    <h1>SC2148 – ShellCheck Wiki</h1>
    <a href="https://github.com/koalaman/shellcheck/wiki/SC2148">See this page on GitHub</a>
    <p style="display: none"><a href="index.html">Sitemap</a></p>
    <hr />
    <h2
id="tips-depend-on-target-shell-and-yours-is-unknown-add-a-shebang">Tips
depend on target shell and yours is unknown. Add a shebang.</h2>
<h3 id="problematic-code">Problematic code:</h3>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="SC2148.html#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="bu">echo</span> <span class="st">&quot;</span><span class="va">$RANDOM</span><span class="st">&quot;</span>   <span class="co"># Does this work?</span></span></code></pre></div>
<h3 id="correct-code">Correct code:</h3>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="SC2148.html#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/bin/sh</span></span>
<span id="cb2-2"><a href="SC2148.html#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="bu">echo</span> <span class="st">&quot;</span><span class="va">$RANDOM</span><span class="st">&quot;</span>  <span class="co"># Unsupported in sh. Produces warning.</span></span></code></pre></div>
<p>or</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="SC2148.html#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/bin/bash</span></span>
<span id="cb3-2"><a href="SC2148.html#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="bu">echo</span> <span class="st">&quot;</span><span class="va">$RANDOM</span><span class="st">&quot;</span>  <span class="co"># Supported in bash. No warnings.</span></span></code></pre></div>
<h3 id="rationale">Rationale:</h3>
<p>Different shells support different features. To give effective
advice, ShellCheck needs to know which shell your script is going to run
on. You will get a different numbers of warnings about different things
depending on your target shell.</p>
<p>If you add a shebang (e.g. <code>#!/bin/bash</code> as the first
line), the OS will use this interpreter when the script is executed, and
ShellCheck will use this shell when offering advice.</p>
<p>If you for any reason can't or won't add a shebang, there are
multiple other ways to let shellcheck know which shell you're coding
for:</p>
<ul>
<li>Specify the shell using the <code>-s</code> or <code>--shell</code>
flag, e.g. <code>shellcheck -s bash myfile</code></li>
<li>Use a shellcheck <a href="directive.html">directive</a>, adding
<code># shellcheck shell=ksh</code> before the first command in the
file.</li>
<li>Give the script a <code>.bash</code>, <code>.ksh</code> or
<code>.dash</code> extension (<code>.sh</code> will not assume
<code>--shell=sh</code> since it's so generic)</li>
</ul>
<h3 id="exceptions">Exceptions</h3>
<p>None. Please either add a shebang, directive, extension or use
<code>-s</code> to maximize ShellCheck's usefulness.</p>
    <hr />
    <p style='font-size: 80%'><a href="../index.html">ShellCheck</a> is a static analysis tool for shell scripts. This page is part of its documentation.</p>
  </body>
</html>


